package com.bree.erp.entity;

import java.util.Collection;
import java.util.Map;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MapKeyColumn;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@NamedQuery(name = Inventory.QUERY_SELECT_ALL_INVENTORY,
		query = "SELECT i FROM Inventory i")
@Entity
public class Inventory implements CrudId<Long> {
	
	public static final String QUERY_SELECT_ALL_INVENTORY = "selectAllInventory";

	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private Long id;
	
	@OneToOne
	private MasterItem masterItem;
	
	@ElementCollection
	@CollectionTable(name="INVENTORY_UNITLEFT")
	@MapKeyColumn(name="UNIT")
	@Column(name="QUANTITY")
	private Map<Unit, Double> units;

	@ElementCollection
	@CollectionTable(name="INVENTORY_UNITTHREASHOLD")
	@MapKeyColumn(name="UNIT")
	@Column(name="THREASHOLD")
	private Map<Unit, Double> threasholds;
		
	@OneToMany(mappedBy="inventory")
	private Collection<InventoryAudit> audits;

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the masterItem
	 */
	public MasterItem getMasterItem() {
		return masterItem;
	}

	/**
	 * @param masterItem the masterItem to set
	 */
	public void setMasterItem(MasterItem masterItem) {
		this.masterItem = masterItem;
	}

	/**
	 * @return the units
	 */
	public Map<Unit, Double> getUnits() {
		return units;
	}

	/**
	 * @param units the units to set
	 */
	public void setUnits(Map<Unit, Double> units) {
		this.units = units;
	}

	/**
	 * @return the threasholds
	 */
	public Map<Unit, Double> getThreasholds() {
		return threasholds;
	}

	/**
	 * @param threasholds the threasholds to set
	 */
	public void setThreasholds(Map<Unit, Double> threasholds) {
		this.threasholds = threasholds;
	}

	/**
	 * @return the audits
	 */
	public Collection<InventoryAudit> getAudits() {
		return audits;
	}

	/**
	 * @param audits the audits to set
	 */
	public void setAudits(Collection<InventoryAudit> audits) {
		this.audits = audits;
	}
	
	
	
}
